<?php

namespace App\Http\Controllers;
use App\Handler\WeChat\SubscribeHandler;
use App\Handler\WeChat\TextHandler;
use App\Wechat\Init;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;

use Illuminate\Support\Facades\Log;

class WeChatController extends BaseController
{
    public function serve()
    {
        try {
            $server = app('easywechat.official_account')->getServer();
            $server
                ->with(SubscribeHandler::class)
                ->with(TextHandler::class);

            return $server->serve();
        }catch (\Exception $e){
            Log::info('request failed: '.$e->getMessage());
        }
    }
    public function jssdkConfig(Request $request)
    {
        $nonceStr = $request->input('nonceStr');
        $timestamp = $request->input('timestamp');
        $wechat = new Init();
        $app = $wechat->getApp();
        $ticket = $app->getTicket();
        $signPackage = $ticket->configSignature('http://hospital.web.wedoctors.com.cn/',$nonceStr,$timestamp);
        return $signPackage;
    }
}
